//
//  XWalletContentTableCell.m
//  Bees
//
//  Created by Xiaohan on 2018/12/22.
//  Copyright © 2018 xiaohan. All rights reserved.
//

#import "XWalletContentTableCell.h"

@interface XWalletContentTableCell()

@end
@implementation XWalletContentTableCell

- (void)setData:(NSArray *)data{
    _data = data;
    [self.table reloadData];
}

- (void)setupUI{
    UIView*backView = [UIView new];
    backView.backgroundColor = UIColor.whiteColor;
    backView.layer.cornerRadius = AdaptedWidth(7.0f);
    [backView.layer setLayerShadow:kShadowColor offset:CGSizeMake(0, 0) radius:6];
    [self.contentView addSubview:backView];
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(kNormalSpace);
        make.right.bottom.mas_equalTo(-kNormalSpace);
    }];
    [backView addSubview:self.table];
    [self.table mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(-AdaptedWidth(10.f));
    }];
    
    UIView*headV = [[UIView alloc]initWithFrame:CGRectMake(0, 0,0, XWalletContentTableHeadHeight)];
    UILabel *tipLab = [UILabel new];
    tipLab.font = kBoldFont(16);
    tipLab.text = XLocalized(@"资产");
    [headV addSubview:tipLab];
    [tipLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(kNormalSpace);
        make.bottom.mas_equalTo(-AdaptedWidth(3));
    }];
    
    UIButton *btn = [UIButton new];
    [btn setImage:IMAGE_NAMED(@"black_add") forState:UIControlStateNormal];
    [headV addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(tipLab.mas_centerY);
        make.right.mas_equalTo(AdaptedWidth(-7));
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    kWeakSelf(self);
    [btn addTapBlock:^(UIButton * _Nonnull btn) {
        !weakself.AddBlock?:weakself.AddBlock();
    }];
    
    self.table.tableHeaderView = headV;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.data.count;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    XWalletContentSubTableCell *cell = [XWalletContentSubTableCell cellForTableView:tableView];
    [cell.iconV sd_setImageWithURL:[NSURL URLWithString:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1547546391297&di=574814b3dbaf0bf3adce6bd893d6b2c3&imgtype=0&src=http%3A%2F%2Fcdn.8btc.com%2Fwp-content%2Fuploads%2F2018%2F04%2F201804230356402774.jpg"]];
    NSString *balance  = [self.data objectOrNilAtIndex:indexPath.row];
    cell.nameLab.text = [balance getUnit];
    cell.valueLab.hidden = IS_Property_Hidden;
    cell.valueLab.text = @"≈ ?????? $";
    if (IS_Property_Hidden) {
        cell.numLab.text = @"****";
    }else{
        cell.numLab.text = [balance getDigital];
    }
  
    return cell;
}

- (UITableView*)table{
    if (!_table) {
        _table = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        _table.delegate = self;
        _table.dataSource = self;
        _table.rowHeight = XWalletContentTableCellHeight;
        _table.separatorStyle = UITableViewCellSeparatorStyleNone;
        _table.scrollEnabled = NO;
        _table.backgroundColor = UIColor.clearColor;
    }
    return _table;
}
@end


@implementation XWalletContentSubTableCell

- (void)setupUI{
    self.iconV = [UIImageView new];
    [self.contentView addSubview:self.iconV];
    [self.iconV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(kNormalSpace);
        make.centerY.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(AdaptedWidth(35), AdaptedWidth(35)));
    }];
    ViewRadius(self.iconV, AdaptedWidth(17.5));
    
    self.nameLab = [UILabel new];
    self.nameLab.font = kBoldFont(16);
    [self.contentView addSubview:self.nameLab];
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconV.mas_right).offset(kNormalSpace);
        make.centerY.mas_equalTo(0);
    }];
    
    self.numLab = [UILabel new];
    self.numLab.font = kBoldFont(16);
    [self.contentView addSubview:self.numLab];
    [self.numLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-kNormalSpace);
        make.top.equalTo(self.iconV.mas_top);
    }];
    
    self.valueLab = [UILabel new];
    self.valueLab.font = kDefaultFont(12);
    self.valueLab.textColor = UIColorHex(#B5B5B5);
    [self.contentView addSubview:self.valueLab];
    [self.valueLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.numLab.mas_right);
        make.bottom.equalTo(self.iconV.mas_bottom);
    }];
  
}

@end
